home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-20 | 2.1 KB | 80 lines | [TEXT/R*ch] |
- Listing 1: QCTools.c
-
- #include “QCAPI.h”
-
- // turn on QC for testing
- void StartQCTesting(void)
- {
- if (QCInstalled())
- if (!QCIsActive())
- QCActivate(NULL);
- }
-
- // turn off QC when we’re done
- voidStopQCTesting(void)
- {
- if (QCInstalled())
- if (QCIsActive())
- QCDeactivate(NULL);
- }
-
- // Turn on arbitrary set of tests depending on build type; we
- // developed these test settings by guess and by gosh. You
- // can define similar functions for other levels of testing.
- void SetDevelopmentTests (void)
- {
- QCErr testErr = noErr;
- testErr = QCSetTestState(qcValidateHandlePointers, TRUE);
- testErr = QCSetTestState(qcDetectWriteToZero, TRUE);
- testErr = QCSetTestState(qcDerefZeroCheck, TRUE);
- testErr = QCSetTestState(qcCheckDisposeRelease, TRUE);
-
- // make sure we see Macsbug error messages
- testErr = QCSetTestState(qcDebugBreaks, TRUE);
- }
-
- Listing 2: QCCallback.c
-
- QC callbacks
- Sample callback which logs the error to a file instead of dropping into the debugger.
- This particular routine logs errors using the string that QC passes.
-
- #include “QCAPI.h”
-
- // the callback routine is defined as “typedef long (*QCCallBack)(QCPBPtr)”;
- // the QCParamPtr tells us what type of test generated the error and what
- // error occured.
- long ErrorToFileCallback(QCPBPtr *theParam)
- {
- QCErr anErr = kQCNoErr;
- StringPtr s = NULL;
-
- // get the error message that would normally go to Macsbug
- anErr = QCGetErrorText(theParam->errorID, s);
- if (anErr == kQCNoErr)
- {
- // log the message to our app log file
- LogEventMessage(kErrorEvt, s);
- }
- else
- LogEventMessage(kErrorEvent, ‘QC internal error’);
- }
-
- // call this routine to make QC start using the callback.
- // In its original form, this routine gets called right before
- // the start of the main event loop. The second parameter
- // to QCInstallHandler is a refcon, so you can pass data to the handler
- // routine when it gets called.
- QCErr MyInstallQCCallBack (void)
- {
- return QCInstallHandler(ErrorToFileCallBack, OL);
- }
-
- // call this routine to make QC stop using the callback.
- // In its original form, this routine gets called right before
- // ExitToShell()
- QCErr MyUnInstallQCCallBack (void)
- {
- return QCRemoveHandler();
- }
-